package com.etc.service;

import com.etc.mapper.CarMapper;
import com.etc.mapper.UserMapper;
import com.etc.pojo.Car;
import com.etc.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class UserServiceImpl {
    @Autowired
    UserMapper userMapper;
    @Autowired
    CarMapper carMapper;

    public void add(User user) {
        userMapper.add(user);
    }

    public User login(User user) {
        return userMapper.login(user);
    }

    public List<Car> listUser1() {
        return carMapper.selectAll();
    }

    public void del(Integer id) {
        carMapper.deleteByPrimaryKey(id);
    }

    public void caradd(Car car) {
        carMapper.insertSelective(car);
    }

    public Car showId(Integer id) {
        return carMapper.selectByPrimaryKey(id);
    }

    public void update(Car car) {
        carMapper.updateByPrimaryKeySelective(car);
    }

    public Car ti(Integer id) {
       return carMapper.selectByPrimaryKey(id);
    }

    public List<Car> mohu(Car car) {
        Example example = new Example(Car.class);
        Example.Criteria criteria = example.createCriteria();
        if (car.getPai()!=null) {
            criteria.andLike("pai", "%" + car.getPai() + "%");
        }
        if (car.getEtc()!=null){
            criteria.andLike("etc", "%" + car.getEtc() + "%");
        }
        List<Car> list = carMapper.selectByExample(example);
        return list;
    }
}
